package com.example.foldertreeview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;


/**
 * Tablayout:打卡记录 列表适配器
 */
public class CallAdapter extends RecyclerView.Adapter<CallAdapter.ViewHolder> {
    //数据源
    private List<String> callList;

    private Context context;

    public CallAdapter(Context context, List<String> callList) {
        this.callList = callList;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_call, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
        final String item = this.callList.get(position);
        holder.NoIdView.setText("No."+(position+1));
        holder.callView.setText(item);

    }

    @Override
    public int getItemCount() {
        return callList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        //序号
        TextView NoIdView;
        //录音文件名
        TextView callView;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            NoIdView = itemView.findViewById(R.id.callId);
            callView = itemView.findViewById(R.id.callName);
        }
    }
}
